/**
 * Created by Administrator on 2016/8/3.
 */
"use strict";
swan_pc
    .controller("AccountSettingController",function($scope,$state,Auth,GetAccountInfo,AccountInfoManage,AccountPasswordChange){
        $scope.AccountManageState=1;
        $scope.AccountManageShow=function(id){
            $scope.AccountManageState=id;
        }
        //获取当前账号信息
        $scope.editUserInfo={};
        $scope.getCurrentAccountInfo=function(){
            GetAccountInfo.get(function(result){
                $scope.editUserInfo=result;
                $scope.userEmail=$scope.editUserInfo.email;
                $scope.userMobile=$scope.editUserInfo.mobile;
            })
        }
        $scope.getCurrentAccountInfo();
        //编辑保存当前账号信息
        $scope.saveUserInfo=function(){
            AccountInfoManage.save($scope.editUserInfo,function(result){
                $scope.getCurrentAccountInfo();
                swal("账号信息修改成功","","success");
            },function(result){
                swal("账号信息修改失败","","error");
            })
        }
        //修改密码
        $scope.passwordConfirm="";
        $scope.changePassword=function(){
            if($scope.editUserInfo.password==null || $scope.editUserInfo.password==""){
                swal("密码不能为空请重新输入");
            } else if($scope.editUserInfo.password!=$scope.passwordConfirm){
                swal("您两次输入的密码不一致，请重新输入");
                $scope.editUserInfo.password="";
                $scope.passwordConfirm="";
            }else{
                AccountPasswordChange.save($scope.passwordConfirm,function(result){
                    //console.log(result);
                    Auth.logout();
                    swal("密码修改成功","","success");
                },function(result){
                    //console.log(result);
                    swal("密码修改失败","","error");
                })
            }
        }
    })
